package com.artqiyi.dollmachine.views.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.artqiyi.dollmachine.R;
import com.artqiyi.dollmachine.common.Base.BaseActivity;
import com.artqiyi.dollmachine.common.constant.Constant;
import com.artqiyi.dollmachine.model.entity.UserInfoBean;
import com.artqiyi.dollmachine.presenter.MinePresenter;
import com.artqiyi.dollmachine.utils.manager.UserInfoManager;
import com.artqiyi.dollmachine.views.widget.ToolBarView;
import com.bumptech.glide.Glide;

import butterknife.Bind;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2017/11/29 0029.
 */

public class MineActivity extends BaseActivity<MinePresenter> implements View.OnClickListener{

    @Bind(R.id.myCoinLayout)
    LinearLayout myCoinLayout;
    @Bind(R.id.couponLayout)
    LinearLayout couponLayout;
    @Bind(R.id.recordLayout)
    LinearLayout recordLayout;
    @Bind(R.id.myDollLayout)
    LinearLayout myDollLayout;
    @Bind(R.id.myOrderLayout)
    LinearLayout myOrderLayout;
    @Bind(R.id.myAddressLayout)
    LinearLayout myAddressLayout;
    @Bind(R.id.inviteLayout)
    LinearLayout inviteLayout;

    @Bind(R.id.avatarImage)
    CircleImageView avatarImage;

    @Bind(R.id.tvNickName)
    TextView tvNickName;
    @Bind(R.id.tvId)
    TextView tvId;
    @Bind(R.id.tvLogout)
    TextView tvLogout;

    private UserInfoBean mUserInfoBean;

    @Override
    public MinePresenter getPresenter() {
        return new MinePresenter();
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_mine;
    }

    @Override
    protected void handleToolBar(ToolBarView toolBar) {
        super.handleToolBar(toolBar);
        toolBar.setTitleText("我的");
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        myCoinLayout.setOnClickListener(this);
        couponLayout.setOnClickListener(this);
        recordLayout.setOnClickListener(this);
        myDollLayout.setOnClickListener(this);
        myOrderLayout.setOnClickListener(this);
        myAddressLayout.setOnClickListener(this);
        inviteLayout.setOnClickListener(this);
        tvLogout.setOnClickListener(this);
        mUserInfoBean = UserInfoManager.getInstance().getUserInfoBean();
        if (mUserInfoBean != null) {
            tvNickName.setText(mUserInfoBean.getNickname());
            tvId.setText(String.format(getString(R.string.mine_id), String.valueOf(mUserInfoBean.getId())));
            Glide.with(MineActivity.this).load(mUserInfoBean.getAvatar()).into(avatarImage);
        }
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.myCoinLayout:
                startActivity(new Intent(MineActivity.this, MineDollCoinActivity.class));
                break;
            case R.id.couponLayout:

                break;
            case R.id.recordLayout:
                startActivity(new Intent(MineActivity.this, MineCatchRecordActivity.class));
                break;
            case R.id.myDollLayout:
                startActivity(new Intent(MineActivity.this, WebViewActivity.class).putExtra(Constant.KEY_MINE_WEBVIEW_TYPE, Constant.MINE_MYWAWA));
                break;
            case R.id.myOrderLayout:
                startActivity(new Intent(MineActivity.this, WebViewActivity.class).putExtra(Constant.KEY_MINE_WEBVIEW_TYPE, Constant.MINE_ORDER));
                break;
            case R.id.myAddressLayout:
                startActivity(new Intent(MineActivity.this, WebViewActivity.class).putExtra(Constant.KEY_MINE_WEBVIEW_TYPE, Constant.MINE_ADDRESS));
                break;
            case R.id.inviteLayout:

                break;
            case R.id.tvLogout:
                startProgressDialog("正在退出...");
                mPresenter.doLogout();
                break;
        }
    }
}
